﻿//同意协议，显示注册按钮
function onxieyi(){
	if(document.getElementById("xieyi").checked==true){
		//alert("选中复选框");
		tj.disabled=false;
	}else{
		tj.disabled=true;
		//test1.setAttribute('defaultChecked',true); 
	}
}

function zhuce(){
	var userid = document.getElementById("userid").value;
	var userpwd = document.getElementById("userpwd").value;
	var repwd = document.getElementById("repwd").value;
	var realname = document.getElementById("realname").value;
	var idcard = document.getElementById("idcard").value;
	var phone = document.getElementById("phone").value;
	var nick = document.getElementById("nick").value;
	var sex1=document.getElementById('sex');
	var sex=sex1[sex1.selectedIndex].value;
	
	var useridtxt=document.getElementById("useridtxt").innerHTML;
    var realnametxt=document.getElementById("realnametxt").innerHTML;
    var userpwdtxt=document.getElementById("userpwdtxt").innerHTML;
    var repwdtxt=document.getElementById("repwdtxt").innerHTML;
    var idcardtxt=document.getElementById("idcardtxt").innerHTML;
    var nicktxt=document.getElementById("nicktxt").innerHTML;
    var phonetxt=document.getElementById("phonetxt").innerHTML;
    
    
	if(userid=="" || userpwd=="" || repwd=="" || realname=="" || idcard =="" ){
		alert("请把资料填写完整！");
		return false;
	}else if(useridtxt!="" || realnametxt!="" || userpwdtxt!="" || repwdtxt!=""
	|| idcardtxt!="" || nicktxt!="" || phonetxt!="" ){
		alert("请根据提示正确填写！");
		return false;
	}else if(document.getElementById("xieyi").checked==false){
		alert("请先同意棋添乐竞技协议，才可以注册");
		return false;
	}else{
		alert("注册成功");
		window.location.href='index.html';
	   	return true;
	}
}
//检测两次输入的密码是否一致，昵称检测
function mimajc(){
	var userpwd = document.getElementById("userpwd").value;
	var repwd = document.getElementById("repwd").value;
	var nick = document.getElementById("nick").value;
	
	if(repwd!=userpwd){
	    document.getElementById("repwdtxt").innerHTML="密码不一致！";
	}else{
	   document.getElementById("repwdtxt").innerHTML="";
	}
	
	//检测昵称的字符串长度是否是十个字符以内。
	var nickLength = 0, lenn = nick.length, charCoden = -1;
	for (var i = 0; i < lenn; i++) {
		charCoden = nick.charCodeAt(i);
		if (charCoden >= 0 && charCoden <= 128) nickLength += 1;
		else nickLength += 2;
	}
	if(nickLength>10){
		document.getElementById("nicktxt").innerHTML="十个字符以内";
		//document.getElementById("nick").focus();
	}else{
	   document.getElementById("nicktxt").innerHTML="";
	}
	
}

function sfzJc(){
    var idcard = document.getElementById("idcard").value;
    lenn = idcard.length;
    console.log(idcard);
    console.log(lenn);
    if(idcard!=""){
    	if(lenn!=18){
            document.getElementById("idcardtxt").innerHTML="身份证错误！";
        }else{
            document.getElementById("idcardtxt").innerHTML="";
		}
    }
}


//密码检测
function pwdjc(){
    var userpwd = document.getElementById("userpwd").value;
    if(userpwd!="" && userpwd.length<6){
        document.getElementById("userpwdtxt").innerHTML="不能少于6个字符";
        //document.getElementById("userpwd").focus();
    }else if(userpwd!="" && userpwd.length>16){
    	document.getElementById("userpwdtxt").innerHTML="不能大于16个字符";
    }else{
    	document.getElementById("userpwdtxt").innerHTML="";
    }
}

//帐号名检测
function useridjc(){
	var userid = document.getElementById("userid").value;
	//检测账号名的字符串长度是否是十个字符以内。
	var realLength = 0, len = userid.length, charCode = -1;
	for (var i = 0; i < len; i++) {
		charCode = userid.charCodeAt(i);
		if (charCode >= 0 && charCode <= 128) realLength += 1;
		else realLength += 2;
	}
	if(realLength>10){
		document.getElementById("useridtxt").innerHTML="十个字符以内！";
		//document.getElementById("userid").focus();
	}else if(userid.indexOf("%") >= 0 || userid.indexOf("#") >=0 || userid.indexOf("^") >=0 || userid.indexOf("&") >=0 
	|| userid.indexOf("*") >=0 || userid.indexOf("`") >=0 || userid.indexOf("/") >=0 || userid.indexOf("'") >=0 
	|| userid.indexOf('"') >=0 || userid.indexOf("!") >=0 || userid.indexOf("?") >=0 || userid.indexOf("￥") >=0
	 || userid.indexOf("？") >=0 || userid.indexOf("；") >=0 || userid.indexOf(";") >=0){
		document.getElementById("useridtxt").innerHTML="存在特殊字符！";
	}else{
		if(userid!=""){
			 document.getElementById("useridtxt").innerHTML="正在检测...";
			 //验证浏览器是否支持ajax
			 try {
				var xmlHttp = new XMLHttpRequest();
			 }catch (trymicrosoft) {
				try {
					xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (othermicrosoft) {
					try {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (failed) {
						xmlHttp = false;
					}
				}
			 }
			//验证账号是否已经存在
			var url = "register_yzid.php?userid="+userid; 
			xmlHttp.open("GET",url,true);
			xmlHttp.onreadystatechange = function(){
				if(xmlHttp.readyState==4){
					var res=xmlHttp.responseText;//res接收返回的结果
					if(res==-1){
						//此账号可以注册
					   document.getElementById("useridtxt").innerHTML="此账号已存在！";
					   //document.getElementById("userid").focus();
					}else if(res==-2){
						document.getElementById("useridtxt").innerHTML="后台服务器繁忙，请稍候再试";
					}else if(res==-3){
						document.getElementById("useridtxt").innerHTML="取不到帐号值";
					}else{
					   document.getElementById("useridtxt").innerHTML="";
					   //document.getElementById("userid").focus();
					}
				}
			}
			xmlHttp.send(null);
		}
	}//end else 验证

}


//身份证号检测
function cardidjc(){
    var idcard = document.getElementById("idcard").value;
    if(idcard!=""){
        try {
            var xmlHttp = new XMLHttpRequest();
        }catch (trymicrosoft) {
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }catch (othermicrosoft) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }catch (failed) {
                    xmlHttp = false;
                }
           }
        }//end ajax try/catch
       var url = "register_yzgd.php?idcard="+idcard;
       xmlHttp.open("GET",url,true);
       xmlHttp.onreadystatechange = function(){
        if(xmlHttp.readyState==4){
           var cardres=xmlHttp.responseText;
           if(cardres==1){
                document.getElementById("idcardtxt").innerHTML=""; 
           }else{
                document.getElementById("idcardtxt").innerHTML="身份证错误！";
                //document.getElementById("idcard").value="";
				//document.getElementById("idcard").focus();
           }
        }
       }
       xmlHttp.send(null);
    }
}
//真实姓名检测
function checkname()
{
	var realname = document.getElementById("realname").value;
	obj=realname.match(/^[\u4e00-\u9fa5]*$/g);
	if(obj==null){
		document.getElementById("realnametxt").innerHTML="姓名必须是汉字！";
		//document.getElementById("realname").value="";
		//document.getElementById("realname").focus();
		return false;
	}else{
		if(realname.length>4 || realname.length<2){
			document.getElementById("realnametxt").innerHTML="2-4个汉字！";
			//document.getElementById("realname").value="";
			//document.getElementById("realname").focus();
		}else{
			document.getElementById("realnametxt").innerHTML="";
		}
		
	}
}
//电话号码检测
function checkphone(){
	var phone = document.getElementById("phone").value;
	if(escape(phone).indexOf("%u")!=-1){
		document.getElementById("phonetxt").innerHTML="不能有汉字！"
		//document.getElementById("phone").focus();
	}else if(phone.match(/\D/)!=null){
		document.getElementById("phonetxt").innerHTML="不能有字母！"
		//document.getElementById("phone").focus();
	}else{
		document.getElementById("phonetxt").innerHTML=""
	}
}

function regisiter(){
    var check = document.getElementById('xieyi');
    console.log(check.checked);//false
	console.log(check);
	if (check.checked==false){
		alert("请先同意必备条款！");
	}else{
      //  alert("注册成功");
		if(document.getElementById("userpwd").value != '' && document.getElementById("idcard").value != '' &&  document.getElementById("userid").value != null && document.getElementById("phonetxt").innerHTML=="" && document.getElementById("realnametxt").innerHTML=="" && document.getElementById("idcardtxt").innerHTML==""){
            var check = confirm('注册成功，点击确认返回首页！');
            if(check) window.location.href='http://www.iipoker.cn/index.html';
		}
		// else if (document.getElementById("phone").value == null && document.getElementById("realname").value == null &&  document.getElementById("userid").value){
         //    alert("请检查输入！");
		// }
		else {
            alert("请检查输入！");
		}

    }
}


